//
//  EMHudManager.m
//  EMMODaliy
//
//  Created by karry on 2020/7/14.
//  Copyright © 2020 miki. All rights reserved.
//

#import "EMHudManager.h"
#import <MBProgressHUD/MBProgressHUD.h>
@interface EMHudManager()

@property (nonatomic, strong) MBProgressHUD *hud;

@end

@implementation EMHudManager

- (MBProgressHUD *)hud{
    if (!_hud) {
        _hud = [[MBProgressHUD  alloc]initWithView:[UIWindow keyWindow]];
        _hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        _hud.bezelView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.85];
        _hud.bezelView.alpha = 0.85;
        _hud.label.textColor = UIColor.whiteColor;
        _hud.contentColor = [UIColor whiteColor];
        _hud.graceTime = 0.3;
        _hud.userInteractionEnabled = NO;
        [[UIWindow keyWindow]addSubview:_hud];
    }
    return _hud;
}

static EMHudManager *_instance = nil;

+ (EMHudManager *)shareManager{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[EMHudManager alloc]init];
    });
    return _instance;
}

- (void)show:(NSString *)text{
    [[UIWindow keyWindow]addSubview:self.hud];

    self.hud.label.text = text;
    [self.hud showAnimated:YES];
}

- (void)showProgress:(CGFloat)progress {
    [[UIWindow keyWindow]addSubview:self.hud];

    self.hud.progress = progress;
    [self.hud showAnimated:YES];
}
- (void)dismiss{
    [self.hud hideAnimated:YES];
}


+ (void)show:(NSString *)text{
    EMHudManager *manager =  [EMHudManager shareManager];
    [manager show:text];
}

+ (void)showProgress:(CGFloat)progress {
    EMHudManager *manager =  [EMHudManager shareManager];
    [manager showProgress:progress];
}

+ (void)show{
    [self show:@""];
}

+ (void)dismiss{
    [[EMHudManager shareManager]dismiss];
}


@end
